// pages/my/appointment-record/appointment-record.js
const controllers = require('../../controllers/ControllerMy').controller;
const app=getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    globalStype:'',
    recordList:[],
    activenav: 0,
    imgurl:'',
    navlist:['全部','审核中','待签到','已完成'],
    navall:true,
    navchoice:'',
    pageNumber: 1,
    pageSize: 10,
    isEnd: false,
  },
  //获取列表
recordList(state){
  controllers.getRecord({
    pageNumber:this.data.pageNumber,
    pageSize:this.data.pageSize,
    shopId:app.globalData.shopId,
    state:state || ''
  }).then(res =>{
    console.log(res);
    if (res.data.list.length != 0) {
      this.setData({
        recordList: this.data.recordList.concat(res.data.list)
      })
    }
    if(res.data.lastPage){
      this.setData({
        isEnd:true
      })
    }
  })
},
  //点击导航列表
  changenav(e) {
    this.setData({
      activenav: e.currentTarget.id
    })
    if (e.currentTarget.id == 0) {
      this.setData({
        navall: true,
        recordList:[],
        navchoice:'',
        isEnd:false,
        pageNumber: 1,
      })
      this.recordList(this.data.navchoice)
    } else if (e.currentTarget.id == 1) {
      this.setData({
        navchoice: 0,
        navall:false,
        recordList:[],
        isEnd:false,
        pageNumber: 1,
      })
      this.recordList(this.data.navchoice)
    } else if (e.currentTarget.id == 2) {
      this.setData({
        navchoice: 1,
        navall:false,
        recordList:[],
        isEnd:false,
        pageNumber: 1,
      })
      this.recordList(this.data.navchoice)
    }else{
      this.setData({
        navchoice: 3,
        navall:false,
        recordList:[],
        isEnd:false,
        pageNumber: 1,
      })
      this.recordList(this.data.navchoice)
    }

    

  },

  //跳转到预约记录详情页
  toRecordDetail(e){
    wx.navigateTo({
      url: '/pages/my/appointment-recordDetail/appointment-recordDetail?id='+e.currentTarget.id,
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({globalStype:app.globalData.globalStype})
    
    this.setData({
      imgurl:app.globalData.IMG_URL
    })

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.setData({
      recordList: [],
      isEnd: false,
      pageNumber: 1,
    })
    this.recordList(this.data.navchoice)

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    if (this.data.isEnd) {
      return;
    } else {
      this.setData({
        pageNumber: this.data.pageNumber + 1,
      });
      this.recordList(this.data.navchoice)
    }
  },

  /**
   * 用户点击右上角分享
   */
  // onShareAppMessage: function () {

  // },


  getDifRecord(index){
    this.setData({
      index:index
    })
  }
})